<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户">
        <el-input v-model="queryParams.createBy"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['work:userTask:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userTaskList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户" align="center" prop="createBy" />
      <el-table-column label="图片地址" align="center" prop="picUrl" width="100">
        <template #default="scope">
          <image-preview :src="scope.row.picUrl" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="视频描述" align="center" prop="des" show-overflow-tooltip/>
      <el-table-column label="视频时长" align="center" prop="seconds" />
      <el-table-column label="任务类型" align="center" prop="taskType" >
        <template #default="scope">
          <span v-if="scope.row.taskType == 1">文生视频</span>
          <span v-if="scope.row.taskType == 2">图+文生视频</span>
        </template>
      </el-table-column>
      <el-table-column label="画面模式" align="center" prop="videoType" >
        <template #default="scope">
          <span v-if="scope.row.videoType == 1">横版</span>
          <span v-if="scope.row.videoType == 2">竖版</span>
          <span v-if="scope.row.videoType == 3">高清横版</span>
          <span v-if="scope.row.videoType == 4">高清竖版</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" >
        <template #default="scope">
          <span v-if="scope.row.status == 0">新建</span>
          <span v-if="scope.row.status == 1">生成中</span>
          <span v-if="scope.row.status == 2">生成成功</span>
          <span v-if="scope.row.status == 3">生成失败</span>
        </template>
      </el-table-column>
      <el-table-column label="失败描述" align="center" prop="failMsg" />
      <el-table-column label="视频地址" align="center" prop="videoUrl">
        <template #default="scope">
          <el-link underline :href="scope.row.videoUrl" type="primary" v-if="scope.row.videoUrl">下载</el-link>
        </template>
      </el-table-column>
      <el-table-column label="taskId" align="center" prop="taskId" show-overflow-tooltip/>
      <el-table-column label="当前接口类型" align="center" prop="nowInterfaceType" />
      <el-table-column label="完成时间" align="center" prop="finishTime" />
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script>
import { listUserTask, getUserTask, delUserTask, addUserTask, updateUserTask } from "@/api/work/userTask";

export default {
  name: "UserTask",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户任务表格数据
      userTaskList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        taskType: null,
        picUrl: null,
        des: null,
        videoType: null,
        costPoint: null,
        status: null,
        videoUrl: null,
        failMsg: null,
        seconds: null,
        taskId: null,
        nowInterfaceType: null,
        hisInterfaceType: null,
        finishTime: null
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户任务列表 */
    getList() {
      this.loading = true;
      listUserTask(this.queryParams).then(response => {
        this.userTaskList = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('work/userTask/export', {
        ...this.queryParams
      }, `userTask_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
